class Solution(object):

    
    def wordBreak(self, s, wordDict):
        """
        :type s: str
        :type wordDict: List[str]
        :rtype: bool
        """
        
        for idx, item in enumerate(wordDict, 1):
            
            if s[:len(item)] == item:
                if len(s) == len(item):
                    return True
                else:
                    if not self.wordBreak(s[len(item):], wordDict) and idx == len(wordDict):
                        return False
                    
                    if not self.wordBreak(s[len(item):], wordDict) and idx != len(wordDict):
                        continue
                    
                    return self.wordBreak(s[len(item):], wordDict)
                        

        
        return False
            
            